
package com.idealighter.game.dictionary.dic;

import com.google.inject.Inject;
import com.google.inject.Singleton;

import com.idealighter.game.dictionary.core.DictionaryTable;
import com.idealighter.game.dictionary.domwrapper.ZhajinhuaRoomDomWrapper;
import com.idealighter.game.dictionary.mapper.ZhajinhuaRoomMapper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Singleton
public class ZhajinhuaRoomDic implements DictionaryTable<ZhajinhuaRoomDomWrapper> {

  private ZhajinhuaRoomMapper mapper;
  private List<ZhajinhuaRoomDomWrapper> list;
  private Map<Integer, ZhajinhuaRoomDomWrapper> map;

  @Inject
  public ZhajinhuaRoomDic(ZhajinhuaRoomMapper mapper) {
    this.mapper = mapper;
    load();
  }

  @Override
  public List<ZhajinhuaRoomDomWrapper> list() {
    return list;
  }

  @Override
  public Map<Integer, ZhajinhuaRoomDomWrapper> map() {

    return map;
  }

  @Override
  public void load() {
    List<ZhajinhuaRoomDomWrapper> list = new ArrayList<>();
    Map<Integer, ZhajinhuaRoomDomWrapper> map = new HashMap<>();

    mapper.selectAll().forEach(dom -> {
      ZhajinhuaRoomDomWrapper domWrapper = new ZhajinhuaRoomDomWrapper(dom);
      map.put(dom.getId(), domWrapper);
      list.add(domWrapper);
    });

    this.list = list;
    this.map = map;
  }

  @Override
  public ZhajinhuaRoomDomWrapper get(int id) {

    return map.get(id);
  }
}
